package main

import (
	"fmt"
	"imooc/retriever/mock"
	"imooc/retriever/real"
)

const url = "https://www.smzdm.com"

type Retriever interface{
	Get(url string) string
}

type Poster interface {
	Post(url string,form map[string]string) string
}

func post(poster Poster) string{
	return poster.Post("https://www.smzdm.com",map[string]string {
		"name" :"wangheng",
		"course":"golang",
	})
}

// 接口组合
type RetrieverPoster interface {
	Poster
	Retriever
}

func session(s RetrieverPoster) string{
	s.Post(url,map[string]string{
		"content":"wangheng",
	})
	return s.Get(url)
}

func download(r Retriever) string{
	return r.Get("http://www.imooc.com")
}

func main(){
	var r RetrieverPoster
	retriever  := mock.Retriever{}
	r = &retriever
	//inspect(r)
	fmt.Println(session(r))
	if mockRetriever,ok := r.(*mock.Retriever);ok{
		fmt.Println(mockRetriever.Content)
	}else{
		fmt.Println("fuck you")
	}

}

func inspect(r Retriever){
	fmt.Printf("%T %v\n",r)
	switch v:= r.(type) {
	case *mock.Retriever:
		fmt.Println("Contents:",v.Content)
	case *real.Retriever:
		fmt.Println("real",v.UserAgent)
	}

}